/**
* 
*/
package com.naiterui.ehp.bs.agent.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.naiterui.ehp.bp.utils.lang.ConfigUtil;
import com.naiterui.ehp.bp.utils.notice.SendMessageUtil;
import com.naiterui.ehp.bp.utils.thread.ThreadPoolUtil;

/**
 * @Description 概述
 */
public class SMSUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger(SMSUtil.class);
    private static String url = ConfigUtil.getString("api.sms.singlesned.url");
    private static SendMessageUtil sendMessageUtil = new SendMessageUtil(url);

    public enum Template {
        /**
         * 密码找回
         */
        PWD(ConfigUtil.getString("message_pwd_tmplate"));

        private String templateId;

        Template(String templateId) {
            this.templateId = templateId;
        }

        public String getTemplateId() {
            return this.templateId;
        }

        public void setTemplateId(String templateId) {
            this.templateId = templateId;
        }
    }

    /**
     * <根据模板发送短信>
     * 
     * @param phone
     * @param tmpl
     * @param args
     *            void <返回值描述>
     * @Throws 异常信息
     * @History 2015-8-21 下午2:30:02 by guoyongxiang
     */
    public static void sendSMS(String phone, Template tmpl, Object... args) {
        String templateId = tmpl.getTemplateId();
        LOGGER.info("[smsSend]短信发送phone: {}, templateId: {}, params: {}", phone, templateId, args);
        try {
            sendMessageUtil.sendSms(phone, templateId, args);
        } catch (Exception e) {
            LOGGER.warn("[smsSend]短信模板内容为空phone: {}, templateId: {}, params: {}", phone, templateId, args, e);
        }
    }

    /**
     * 异步短信发送方法 SMSUtil.asyncSendSMS()
     * 
     * @Date 2017年10月31日
     * @since 2.9.2
     * @param phone
     * @param tmpl
     * @param args
     */
    public static void asyncSendSMS(final String phone, final Template tmpl, final Object... args) {
        ThreadPoolUtil.execute(() -> SMSUtil.sendSMS(phone, tmpl, args));
    }
}
